def the_nearest_Simple():
    entered_Numbers = input().split()
    if len(entered_Numbers) != 3:
        return "Wrong input"
    dictionary_of_Numbers = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }
    
    number = dictionary_of_Numbers. get (entered_Numbers [0], 0) * 100+ dictionary_of_Numbers. get (entered_Numbers [1], 0) * 10 + dictionary_of_Numbers. get (entered_Numbers [2], 0)
    if not 100 <= number <= 999:
        return "Wrong input"
    def number_Simple (n):
        if n <= 1:
            return False
        for i in range(2, int(n ** 0.5) + 1):
            if n % i == 0:
                return False
        return True
    less = more = number
    while True:
        if number_Simple (less):
            return less
        if number_Simple (more):
            return more
        less -= 1
        more += 1
print(the_nearest_Simple())
